import pymysql
import pandas as pd

conn = pymysql.connect(
    host="localhost",
    user="root",
    password="123456",
    database="rpa",
    charset="utf8mb4"
)

"""
cursor = conn.cursor()

sql_str = "select * from companyaccount"
sql_str1 = "update companyaccount set CompanyName = '小腾' where AccountID = 101"

cursor.execute(sql_str)
result = cursor.fetchall()

for row in result:
    print(row)

conn.close()
"""


def mysql_select(tableName):
    try:
        with conn.cursor() as cursor:
            sqlStr = f"SELECT * FROM {tableName}"
            cursor.execute(sqlStr)
            result = cursor.fetchall()
            return result
    finally:
        conn.close()


arrMysql = []

for row in mysql_select("emp"):
    arrMysql.append(list(row))

df = pd.DataFrame(arrMysql)

print(df.values.tolist())
print(df)
